package com.qifenqian.turbot.module.ui.marketing

import android.content.Context
import android.content.Intent
import android.support.v7.widget.LinearLayoutManager
import com.qifenqian.turbot.R
import com.qifenqian.turbot.base.BaseActivity
import com.qifenqian.turbot.module.adapter.itemdecoration.LinearItemDecoration
import com.qifenqian.turbot.module.adapter.marketing.FreeTimeDiscountAdapter
import com.qifenqian.turbot.module.contract.MarketingContract
import com.qifenqian.turbot.module.entity.response.marketing.FreeTimeDiscountDetailEntity
import com.qifenqian.turbot.module.presenter.MarketingPresenter
import kotlinx.android.synthetic.main.activity_free_time_discount.*

/**
 * @author H
 * @createDate 2019/1/4 9:26
 * @description 闲时折扣
 * @see
 * @since
 */
class FreeTimeDiscountActivity : BaseActivity<MarketingPresenter, MarketingContract.View>(), MarketingContract.View {

    companion object {
        fun startThis(context: Context) {
            val intent = Intent(context, FreeTimeDiscountActivity::class.java)
            context.startActivity(intent)
        }
    }

    override fun bindLayoutId(): Int = R.layout.activity_free_time_discount

    override fun bindPresenter(): MarketingPresenter? = MarketingPresenter(this, this)

    private var mList = mutableListOf("1", "2")
    private val mFreeTimeDiscountAdapter: FreeTimeDiscountAdapter? = null
    override fun initial() {
        mPresenter?.getFreeTimeDiscount()
        btn_free_time_discount_add.setOnClickListener {
            FreeDiscountEditActivity.startThis(this, ACTION_FREE_DISCOUNT_ADD)
        }
        val mFreeTimeDiscountAdapter = FreeTimeDiscountAdapter(mList)
        rv_free_time_discount.layoutManager = LinearLayoutManager(this)
        rv_free_time_discount.addItemDecoration(LinearItemDecoration(this, spaceWidth = 16))
        rv_free_time_discount.adapter = mFreeTimeDiscountAdapter
    }

    private var mFreeTimeDiscountDetailEntity: FreeTimeDiscountDetailEntity? = null
    override fun getFreeTimeDiscountResult(isSuccess: Boolean, code: Int, msg: String?, t: FreeTimeDiscountDetailEntity?) {
        if (isSuccess) {
            mFreeTimeDiscountDetailEntity = t
            mList.clear()
//            mList.addAll()
            mFreeTimeDiscountAdapter?.notifyDataSetChanged()
        } else {
//            showErrorPage(View.OnClickListener { mPresenter?.getFreeTimeDiscount() }, msg)
        }
    }
}
